/*---------------------------------------------------------------------*
 * api
 *---------------------------------------------------------------------*/

#ifndef __QC_API_INIT_H__
#define __QC_API_INIT_H__

#include "stdint.h"
#include "api_cfg.h"

/*---------------------------------------------------------------------*
 * source
 *---------------------------------------------------------------------*/
#ifdef QC_API_EN
#include "qcom.h"
#endif

#ifdef MB_API_EN
#include "mbcom.h"
#include "mbmaster.h"
#endif

#ifdef PID_API_EN
#include "pid.h"
#endif

#ifdef PT_API_EN
#include "templib.h"
#include "pt100.h"
#endif

#ifdef TC_API_EN
#include "tc_cal.h"
#endif

#ifdef TCTR_API_EN
#include "tempctrlib.h"
#endif

#ifdef HTTR_API_EN
#include "humitempctrlib.h"
#endif

#ifdef GUS_API_EN
#include "mbcom.h"
#include "mbmaster.h"
#include "dgus_dev.h"
#include "vgus_dev.h"
#include "dgusii_dev.h"
#endif

/*---------------------------------------------------------------------*
 * api list define
 *---------------------------------------------------------------------*/
typedef const struct
{
#ifdef QC_API_EN
	void (*qc_mb_poll)(qc_obj_type *obj);
	void (*qc_poll)(qc_obj_type *obj);

	void (*qc_obj_init)(qc_obj_type *obj, qc_cmd_type *clist, uu8 cnum, uu8 stcnum);
	void (*mqc_cmd_next)(qc_obj_type *obj);
	void (*mqc_cmd_clr)(qc_obj_type *obj);
	uint8_t (*mqc_dyna_cmd_req)(qc_obj_type *obj, qc_cmd_type *cmd);
	uint8_t (*mqc_stc_cmd_req)(qc_obj_type *obj, uint8_t cmd_site, qc_cmd_type *cmd);
	uint8_t (*mqc_stc_cmd_del)(qc_obj_type *obj, uint8_t cmd_site);
	uint8_t (*mqc_cmd_ready_num)(qc_obj_type *obj);
	uint8_t (*mqc_cmd_idle_num)(qc_obj_type *obj);
	void (*qc_exe_success)(qc_obj_type *obj);
	void (*qc_exe_fail)(qc_obj_type *obj);

	void (*qc_rcv_byte)(qc_obj_type *obj, uu8 dat);
	uint8_t (*qc_data_send)(qc_obj_type *obj, void (*send)(uint8_t), uint8_t len);
	void (*qc_send_end)(qc_obj_type *obj);
	void (*qc_timer_handle)(qc_obj_type *obj);
	void (*qc_package_send)(qc_obj_type *obj, uu8 len);
#endif

#ifdef MB_API_EN
	void (*mb_poll)(mb_obj_type *mb_obj);
	void (*mb_obj_init)(mb_obj_type *mb_obj);
	void (*mb_package_send)(mb_obj_type *mb_obj);
	uint16_t (*mb_crc)(uint8_t *pucFrame, uint16_t usLen);

	uint8_t (*mb_data_send)(mb_obj_type *mb_obj, void (*send)(uint8_t), uint8_t len);
	uint8_t (*mb_data_send_u32_fifo)(mb_obj_type *mb_obj, volatile uint32_t *pdat, uint8_t len);
	uint8_t (*mb_data_send_u16_fifo)(mb_obj_type *mb_obj, volatile uint16_t *pdat, uint8_t len);
	uint8_t (*mb_data_send_u8_fifo)(mb_obj_type *mb_obj, volatile uint8_t *pdat, uint8_t len);
	void (*mb_send_end)(mb_obj_type *mb_obj);

	void (*mb_data_rcv)(mb_obj_type *mb_obj, uint8_t dat);
	void (*mb_data_rcv_u32_fifo)(mb_obj_type *mb_obj, volatile uint32_t *pdat, uint16_t len);
	void (*mb_data_rcv_u16_fifo)(mb_obj_type *mb_obj, volatile uint16_t *pdat, uint16_t len);
	void (*mb_data_rcv_u8_fifo)(mb_obj_type *mb_obj, volatile uint8_t *pdat, uint16_t len);
	uint8_t (*mb_data_pre_rcv)(mb_obj_type *mb_obj);
	void (*mb_data_rcv_directly)(mb_obj_type *mb_obj, uint8_t dat);

	void (*mb_rtu_timer_run)(mb_obj_type *mb_obj); // 1ms中断中调用

	void (*mmb_cmd_buff_init)(mb_obj_type *mb_obj, mb_cmd_buff_type *pBuff, uint8_t mbCBuffSize, uint8_t mbSCBuffSize);
	uint8_t (*mmb_os_stc_cmd_req)(mb_obj_type *mb_obj, uint8_t CmdSite, mb_cmd_buff_type *cmd);
	uint8_t (*mmb_os_dyna_cmd_req)(mb_obj_type *mb_obj, mb_cmd_buff_type *cmd);
	uint8_t (*mmb_os_stc_cmd_del)(mb_obj_type *mb_obj, uint8_t CmdSite);
	uint8_t (*mmb_stc_cmd_req)(mb_obj_type *mb_obj, uint8_t CmdSite, mb_cmd_buff_type *cmd);
	uint8_t (*mmb_dyna_cmd_req)(mb_obj_type *mb_obj, mb_cmd_buff_type *cmd);
	uint8_t (*mmb_stc_cmd_del)(mb_obj_type *mb_obj, uint8_t CmdSite);
	uint8_t (*mmb_cmd_ready_num)(mb_obj_type *mb_obj);
	uint8_t (*mmb_cmd_idle_num)(mb_obj_type *mb_obj);
	void (*mmb_cmd_clr)(mb_obj_type *mb_obj);
#endif

#ifdef PID_API_EN
	void (*IndPid)(pid_type *pid);

	void (*PidClr)(pid_type *pid);
	void (*PidDvClr)(pid_type *pid);
	void (*PidOutWeaken)(pid_type *pid, float Coef);
	void (*PidUpdate)(pid_type *pid, uint16_t *ParTab, float DutyMin, float DutyMax);

	uint8_t (*PidAutoSet)(pid_tune_type *tune_obj);
	void (*PidAutoSetStart)(pid_type *pid, pid_tune_type *tune_obj);
	void (*PidAutoSetExit)(pid_tune_type *tune_obj);

	int32_t (*q_pid_update)(q_pid_type *pid);
	int32_t (*q_pid_cal)(q_pid_type *pid);
	void (*q_pid_clr)(q_pid_type *pid);
	void (*q_pid_dv_clr)(q_pid_type *pid);
#endif

#ifdef PT_API_EN
	float (*Pt100_ResToTemp)(float m_Res);
	float (*Pt100_TempToRes)(float m_Temp);
	void (*temp_cal_imap)(TEMP_OBJ_Type *TempObj);
	void (*temp_cal_pbpk)(TEMP_OBJ_Type *TempObj);
	float (*pt100_cal_pbpk)(pt100_type *pt);
	float (*pt100_cal_imap)(pt100_type *pt);
#endif

#ifdef TC_API_EN
	float (*tc_k_cal_pbpk)(tc_cal_type *tc);
	float (*tc_k_cal_imap)(tc_cal_type *tc);
	float (*tc_r_cal_pbpk)(tc_cal_type *tc);
	float (*tc_r_cal_imap)(tc_cal_type *tc);
	float (*tc_e_cal_pbpk)(tc_cal_type *tc);
	float (*tc_e_cal_imap)(tc_cal_type *tc);
	float (*tc_j_cal_pbpk)(tc_cal_type *tc);
	float (*tc_j_cal_imap)(tc_cal_type *tc);
	float (*tc_s_cal_pbpk)(tc_cal_type *tc);
	float (*tc_s_cal_imap)(tc_cal_type *tc);
	float (*tc_t_cal_pbpk)(tc_cal_type *tc);
	float (*tc_t_cal_imap)(tc_cal_type *tc);
	float (*tc_n_cal_pbpk)(tc_cal_type *tc);
	float (*tc_n_cal_imap)(tc_cal_type *tc);
	float (*tc_b_cal_pbpk)(tc_cal_type *tc);
	float (*tc_b_cal_imap)(tc_cal_type *tc);
#endif

#ifdef TCTR_API_EN
	void (*temp_box_ctr)(temp_box_ctr_type *TempCtrPar);
#endif

#ifdef HTTR_API_EN
	void (*HT_Control)(HUMITEMP_CTR_PAR_Type *CtrPar);
#endif

#ifdef GUS_API_EN
	void (*dgus_poll)(mb_obj_type *mb_obj);
	void (*dgusii_poll)(mb_obj_type *mb_obj);
	void (*vgus_poll)(mb_obj_type *mb_obj);
	void (*vgus_page_set)(mb_obj_type *mb_obj, uint16_t *page, void (*call_back)(uint8_t, uint8_t));
	void (*vgus_pv_read)(mb_obj_type *mb_obj, uint16_t *dat, uint16_t addr, uint16_t Len, void (*call_back)(uint8_t, uint8_t));
	void (*vgus_pv_write)(mb_obj_type *mb_obj, uint16_t *dat, uint16_t addr, uint16_t Len, void (*call_back)(uint8_t, uint8_t));
#endif

	const char *info;
} api_list_type;

/*---------------------------------------------------------------------*
 * cfg
 *---------------------------------------------------------------------*/
typedef struct
{
	uint16_t (*lib_tick_get)(void);
	void (*lib_delay_0_5us)(uint16_t u0_5us);
	void (*lib_delay_us)(uint16_t us);
	void (*lib_delay_ms)(uint16_t ms);
	void (*lib_check_hook)(int32_t st);
	void (*lib_os_lock)(void);
	void (*lib_os_unlock)(void);

} lib_cfg_type;

/*---------------------------------------------------------------------*
 * api call interface
 *---------------------------------------------------------------------*/
#define lib ((api_list_type *)(lib_rom_base))
#define lib_hal ((lib_cfg_type *)(lib_hal_rom_base))

/*---------------------------------------------------------------------*
 * EOF
 *---------------------------------------------------------------------*/
#endif
